package com.sctvcloud.longchang.ui.adapter.holder;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import com.ruihang.generalibrary.ui.adapter.holder.BaseRecylerHolder;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.ruihang.generalibrary.utils.DateUtils;
import com.sctvcloud.longchang.R;
import com.sctvcloud.longchang.beans.FProgram;
import com.sctvcloud.longchang.ui.utils.GlideUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ProgramItemHolder extends BaseRecylerHolder<FProgram> implements View.OnClickListener {
    @BindView(R.id.program_img)
    protected ImageView program_img;
    @BindView(R.id.program_icon)
    protected ImageView program_icon;
    @BindView(R.id.program_title)
    protected CustomFontTextView program_title;
    @BindView(R.id.program_time)
    protected CustomFontTextView program_time;

    private FProgram t;
    private OnProgramItemClickListener listener;

    public ProgramItemHolder(Context context, View itemView, OnProgramItemClickListener listener) {
        super(context, itemView);
        this.listener = listener;
        itemView.setOnClickListener(this);
    }

    @Override
    public void setData(FProgram t) {
        this.t = t;
        GlideUtil.getGlideWithLarge169CenterCrop(context, t.getProgrammeImage()).into(program_img);
        program_title.setText(t.getProgrammeTitle());
        String timeStr = DateUtils.timeAgo(DateUtils.getDataDate(t));
        program_time.setText(timeStr);
        if(t.isSelect()){
            program_title.setTextColor(context.getResources().getColor(R.color.colorHomeText));
            program_icon.setImageResource(R.mipmap.icon_home_onair);
        }else{
            program_title.setTextColor(context.getResources().getColor(R.color.black_2));
            program_icon.setImageResource(R.mipmap.icon_home_play);
        }
    }

    @Override
    protected void initInject() {
        ButterKnife.bind(this, itemView);
    }

    @Override
    public void onClick(View v) {
        if (null != listener) {
            listener.OnProgramItemClick(t);
        }
    }

    public interface OnProgramItemClickListener {
        void OnProgramItemClick(FProgram fp);
    }
}
